package com.zhiyume.service;

import com.zhiyume.api.util.ApiClassifyEnum;
import com.zhiyume.api.util.ApiConstants;
import com.zhiyume.api.util.ApiFloorEnum;
import com.zhiyume.api.util.ApiOperateEnum;
import com.zhiyume.dao.api.*;
import com.zhiyume.dao.entity.*;
import com.zhiyume.page.PageReq;
import com.zhiyume.service.util.DateUtil;
import com.zhiyume.service.util.GenerateKeyUtil;
import com.zhiyume.util.TypeConstants;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by wang on 17/9/28.
 */
@Service
public class DataService {

    @Autowired
    private TInformationMapper tInformationMapper;

    @Autowired
    private TCmsTemplateMapper tCmsTemplateMapper;

    @Autowired
    private TCmsPlaceMapper tCmsPlaceMapper;

    @Autowired
    private TDramaMapper tDramaMapper;

    @Autowired
    private TPersonMapper tPersonMapper;

    @Autowired
    private TCareerMapper tCareerMapper;

    @Autowired
    private TDramaPersonMapper tDramaPersonMapper;

    @Autowired
    private TInformationMapper informationMapper;

    @Autowired
    private TInformationSelfMapper tInformationSelfMapper;

    @Autowired
    private InformationService informationService;

    @Autowired
    private TCommentMapper commentMapper;

    @Autowired
    private TAdminMapper tAdminMapper;

    @Autowired
    private TCmsHomeMapper tCmsHomeMapper;

    private static final Logger logger = LoggerFactory.getLogger(DataService.class);



    private static List<String> codes = new ArrayList<String>(){{
        add("10");
        add("30");
        add("60");
    }};

    private static List<Integer> careers = new ArrayList<Integer>(){{
        add(1);
        add(2);
        add(3);
    }};

    private static List<String> imgUrls = new ArrayList<String>(){{
//        add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4289987850,2027981123&fm=11&gp=0.jpg");
//        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3287406161,1370230616&fm=11&gp=0.jpg");
//        add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3180783630,3325771437&fm=27&gp=0.jpg");
//        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2326007109,671296332&fm=27&gp=0.jpg");
//        add("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3954621767,2490461867&fm=11&gp=0.jpg");
//        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2875524332,436336741&fm=11&gp=0.jpg");
//        add("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4155809725,2453290283&fm=27&gp=0.jpg");
//        add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3255078302,3579388021&fm=200&gp=0.jpg");
        add("http://img02.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59dcd401f3e865c1916dc743_240x140!.jpg@@@@http://img02.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59dcd32cf3e865c1916dc70c_240x140!.jpg@@@@http://img03.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59dcd308f3e865c1916dc6f7_240x140!.jpg");
        add("http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59dccfb4f3e865c1916dc638_240x140!.jpg@@@@http://zhiyume-img.oss-cn-beijing.aliyuncs.com/information/20171021102509_psb.jpg?Expires=1823912710&OSSAccessKeyId=LTAI8hTtxsI962e5&Signature=ozMgzMYqOjRI7X%2BSQhdd8mFvz3Y%3D@@@@http://zhiyume-img.oss-cn-beijing.aliyuncs.com/information/20171021102509_Linux%E5%91%BD%E4%BB%A4.png?Expires=1823912710&OSSAccessKeyId=LTAI8hTtxsI962e5&Signature=JefpF9Nhx08eCJebHrba6YaKtsE%3D");
//        add("http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59dccfb4f3e865c1916dc638_240x140!.jpg@@@@http://zhiyume-img.oss-cn-beijing.aliyuncs.com/information/20171021102747_psb.jpg?Expires=1823912867&OSSAccessKeyId=LTAI8hTtxsI962e5&Signature=mI13F4vEFp9PNYcL2%2BYV2dsdN9U%3D@@@@http://zhiyume-img.oss-cn-beijing.aliyuncs.com/information/20171021102747_Linux%E5%91%BD%E4%BB%A4.png?Expires=1823912867&OSSAccessKeyId=LTAI8hTtxsI962e5&Signature=abfGLWTR35NWzUhATRguHwDRXXE%3D");
        add("http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5e4c9f3e8311fe274652b_240x140!.jpg@@@@http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5dc64f3e8f1d8f0465267_240x140!.jpg@@@@http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5dc60f3e8311fe27464ea_240x140!.jpg");
        add("http://img03.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5dc60f3e8311fe27464ed_240x140!.jpg@@@@http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5dc28f3e8311fe27464d9_240x140!.jpg@@@@http://img02.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da83f3e8f1d8f04651ee_240x140!.jpg");
        add("http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da91f3e8f1d8f0465237_240x140!.jpg@@@@http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da91f3e8311fe27464c3_240x140!.jpg@@@@http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da7ff3e8311fe2746474_240x140!.jpg");
        add("http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da79f3e8f1d8f04651c9_240x140!.jpg@@@@http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da8cf3e8f1d8f0465228_240x140!.jpg@@@@http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da69f3e8311fe2746428_240x140!.jpg");
        add("http://img03.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da63f3e8f1d8f0465174_240x140!.jpg@@@@http://img03.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da63f3e8f1d8f0465174_240x140!.jpg@@@@http://img01.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5da63f3e8f1d8f046517c_240x140!.jpg");
        add("http://img.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5d9c5f3e8f1d8f0465118_240x140!.jpg@@@@http://img03.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f2ccbff3e8311fe2739855_240x140!.jpg@@@@src=\"http://img02.static.xinhua-news.com/imageServer/image/bba04f1f3972a8b1/59f5d348f3e8311fe2746082_240x140!.jpg");
    }};

    private static List<String> urls = new ArrayList<String>(){{
        add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4289987850,2027981123&fm=11&gp=0.jpg");
        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3287406161,1370230616&fm=11&gp=0.jpg");
        add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3180783630,3325771437&fm=27&gp=0.jpg");
        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2326007109,671296332&fm=27&gp=0.jpg");
        add("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3954621767,2490461867&fm=11&gp=0.jpg");
        add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2875524332,436336741&fm=11&gp=0.jpg");
        add("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4155809725,2453290283&fm=27&gp=0.jpg");
        add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3255078302,3579388021&fm=200&gp=0.jpg");
    }};

    private static List<String> classify = new ArrayList<String>(){{
        add("1");
        add("2");
        add("3");
        add("4");
        add("5");
    }};


    private static List<String> first = new ArrayList<String>(){{
        add("赵");
        add("钱");
        add("孙");
        add("李");
        add("周");
        add("吴");
        add("郑");
        add("王");
        add("白");
        add("雷");
    }};

    private static List<String> second = new ArrayList<String>(){{
        add("学");
        add("一");
        add("美");
        add("和");
        add("晋");
        add("思");
        add("古");
        add("开");
        add("博");
        add("子");
    }};

    private static List<String> last = new ArrayList<String>(){{
        add("丽");
        add("军");
        add("俊");
        add("卓");
        add("宾");
        add("治");
        add("修");
        add("潼");
        add("婷");
        add("军");
    }};

    private static List<String> mobile1 = new ArrayList<String>(){{
        add("180");
        add("189");
        add("170");
        add("133");
        add("154");
        add("135");
    }};


    private static List<String> mobile2 = new ArrayList<String>(){{
        add("9876");
        add("0952");
        add("8709");
        add("3342");
        add("2498");
        add("7652");
    }};


    private static List<String> mobile3 = new ArrayList<String>(){{
        add("981");
        add("200");
        add("872");
        add("092");
        add("844");
        add("762");
    }};

    private static List<String> themes = new ArrayList<String>(){{
        add("偶像剧");
        add("仙侠剧");
        add("科幻");
        add("惊悚");
        add("悬疑");
        add("恐怖");
        add("喜剧");
        add("刑侦");
        add("都市");
        add("校园");
    }};


    private static List<String> informations = new ArrayList<String>(){{
        add("反黑陈凤翔结局是什么\n" +
                "\n" +
                "电视剧《反黑》正在热播中，剧中主角卧底探员陈凤翔一角由山鸡哥陈小春饰演。那么反黑陈凤翔结局是什么？陈凤翔最后和谁在一起了？下面就和小编一起来看看！\n" +
                "\n" +
                "剧中陈凤翔在破获了一场大型案件后转为文员，在八年之后又被反黑组重新召回。\n" +
                "\n" +
                "很多关注该剧的网友对于剧中陈小春饰演的陈凤翔的结局都充满了十足的关注，而陈凤翔在剧中调查龙头棍失踪一案时，更是卷入了香港黑-社-会百年历史的惊天大阴谋中。据悉，陈凤翔最后的结局应该是没有死，虽然陈凤翔几度挣扎在垂死边缘，但是凭借聪明的大脑更是一次次逃离死亡边缘。主角是不会轻易领盒饭的~否则剧就不好看了~");
        add("两千多特效镜头搭载超现实布景 近万人团队高还原度呈现九州\n" +
                "\n" +
                "电影《鲛珠传》讲述了飞贼泥空空、女捕快黑羽和王子蛤蜊的奇幻冒险故事，制作特辑中进一步呈现了《鲛珠传》诞生的全过程。在为期近两年的拍摄过程中，主创团队费尽心血以求最大程度还原九州。视频里特写了工作室中密密麻麻的概念设计图稿，共计超过3000张，几幅细腻恢宏的画稿，让观众得以窥见导演设想中九州最初的模样。而2130个特效镜头则完美地将画稿中的九州呈现于观众眼前，大量闪现的绿幕足见特效部分在片中占据的比重之大。为追求更加真实的场景观感，《鲛珠传》亦搭建了五万余平米的置景，片中镇虎司、夜沼地穴等关键场景的一草一木，皆来自于实景搭建。参演与工作人员共计近万人，七百多个日夜的努力，让梦一般的奇幻世界成为现实。");
        add("那年花开月正圆周莹抢沈星移生意是怎么回事？那年花开月正圆最新剧情中，周莹和沈星移差一点就要反目了呢，到底是因为什么？之后沈星移又为什么要离家出走呢？\n" +
                "\n" +
                "那年花开月正圆第53集剧情\n" +
                "\n" +
                "那年花开月正圆53集周莹抢沈星移生意\n" +
                "\n" +
                "沈星移问周莹为什么要抢自己的生意，周莹称他只是碰巧撞在了自己的枪口上，沈星移明知周莹当初是为了自己才来的上海，却不明白她这么快就翻脸是为了那般。\n" +
                "\n" +
                "回到泾阳后，周莹对赵白石说自己要上京城告御状，赵白石知道这其中牵扯到了贝勒爷，与他作对无异于以卵击石，因此再三阻拦，可周莹却不肯听劝。\n" +
                "\n" +
                "周莹将沈四海是害得吴家东院家破人亡的罪魁祸首之事告诉了沈星移，沈星移又惊又气，回去质问自己的父亲，可沈四海却理直气壮地说，自己这是要为沈月生报仇，沈星移苦劝无果，十分苦闷。");
        add("那片星空那片海2墨痕是好人还是坏人\n" +
                "\n" +
                "电视剧《那片星空那片海2》即将开播，在那片星空那片海第一季中，有人一直想致吴居蓝死，那就是大家口中的坏人，在第二季中新出现的人物墨痕是好人还是坏人呢？\n" +
                "\n" +
                "从曝光的预告片中，可以看出墨痕应该不是什么善类。他和吴居蓝都是鲛人，但却三番五次想杀吴居蓝。还有墨痕似乎在进行着某种不为人知的任务，以此推测墨痕是坏人。\n" +
                "\n" +
                "那片星空那片海2真实身份是什么\n" +
                "\n" +
                "《那片星空那片海2》延续第一季鲛人与人类之间的线索，以繁华盛唐时期恢弘大气的航海史诗为背景，讲述一个出身造船世家的平凡女孩和鲛人王之间真挚动人的爱情故事。剧中墨痕是一个新加入的角色，他也是一名鲛人。\n" +
                "\n");
        add("星座：狮子座（泰国使用的是新十三星座，和十二星座不同，在中国是处女座）\n" +
                "\n" +
                "素格力·威塞哥是一名属于Exact公司的泰国演员和歌手。素格力在第三季的The Star比赛中获得了第二名。之后，他演唱的第一首非常受欢迎的歌曲是《I Need Somebody》。素格力在2008年被泰国《Positoning》杂志列为泰国最有影响力的人，其他人包含了泰国在政治方面及社会方面的重要人物。\n" +
                "\n" +
                "命中注定我爱你泰剧剧情介绍\n" +
                "\n" +
                "讲述了善良平凡的“便利贴女孩(esther饰)和因无子嗣深陷不能继承家族事业危机的完美男(bie饰)在一次豪华旅行中共度一夜，因不小心怀孕不得不结婚，并在相处的过程中找到真爱的故事。");
    }};


    private static List<String> contents = new ArrayList<String>(){{
        add("深度好文");
        add("赞");
        add("不错");
        add("原来是这样");
        add("可以可以");
    }};

    /**
     * 删除模板
     * @return
     */
    public void delTemplate(){
        TCmsTemplateCriteria tArticleCriteria = new TCmsTemplateCriteria();
        TCmsTemplateCriteria.Criteria c = tArticleCriteria.createCriteria();
        tCmsTemplateMapper.deleteByExample(tArticleCriteria);
    }

    /**
     * 添加基础模板
     * @return
     */
    public void addTemplate(){
        delTemplate();

        int a = 1;
        for(;a<6;a++){
            TCmsTemplate t1 = new TCmsTemplate();
            t1.setId(GenerateKeyUtil.generationPK());
            t1.setName("首页"+classify.get(a-1)+"模板");

            t1.setClassify(classify.get(a-1));
            t1.setStatus("0");
            t1.setRemark("无效的模板");
            tCmsTemplateMapper.insert(t1);
        }

        int b =1 ;
        for(;b<6;b++){
            TCmsTemplate t2 = new TCmsTemplate();
            t2.setId(GenerateKeyUtil.generationPK());
            t2.setName("首页"+classify.get(b-1)+"模板");

            t2.setClassify(classify.get(b-1));
            t2.setStatus("1");

            tCmsTemplateMapper.insert(t2);
        }

    }

    public void delTCmsPlace(){
        TCmsPlaceCriteria tCmsPlaceCriteria = new TCmsPlaceCriteria();
        TCmsPlaceCriteria.Criteria c = tCmsPlaceCriteria.createCriteria();
        tCmsPlaceMapper.deleteByExample(tCmsPlaceCriteria);
    }

    public void delDramas(){
        TDramaCriteria t = new TDramaCriteria();
        TDramaCriteria.Criteria c = t.createCriteria();
        tDramaMapper.deleteByExample(t);
    }

    public void addTCmsPlace(){
        delTCmsPlace();

        TCmsPlace p = new TCmsPlace();
        p.setSortNo(1);
        p.setId(GenerateKeyUtil.generationPK());
        p.setStatus("1");
        p.setCode("10");
        tCmsPlaceMapper.insert(p);
        TCmsPlace p1 = new TCmsPlace();
        p1.setSortNo(2);
        p1.setId(GenerateKeyUtil.generationPK());
        p1.setStatus("1");
        p1.setCode("30");
        tCmsPlaceMapper.insert(p1);
        TCmsPlace p2 = new TCmsPlace();
        p2.setSortNo(3);
        p2.setId(GenerateKeyUtil.generationPK());
        p2.setStatus("1");
        p2.setCode("60");
        tCmsPlaceMapper.insert(p2);
    }


    public void delCareer(){
        TCareerCriteria t = new TCareerCriteria();
        TCareerCriteria.Criteria c = t.createCriteria();
        tCareerMapper.deleteByExample(t);
    }

    public void addCareer(){

        TCareer c1 = new TCareer();
        c1.setId(TypeConstants.PersonConstant.PERSON_ACTOR);
        c1.setCareerName("演员");
        c1.setCareerDescript("这就是一个演员");
        tCareerMapper.insert(c1);

        TCareer c2 = new TCareer();
        c2.setId(TypeConstants.PersonConstant.PERSON_WRITER);
        c2.setCareerName("编剧");
        c2.setCareerDescript("这就是一个编剧");
        tCareerMapper.insert(c2);

        TCareer c3 = new TCareer();
        c3.setId(TypeConstants.PersonConstant.PERSON_DIRECTOR);
        c3.setCareerName("导演");
        c3.setCareerDescript("这就是一个导演");
        tCareerMapper.insert(c3);

    }


    public void delActor(){
        TPersonCriteria t = new TPersonCriteria();
        TPersonCriteria.Criteria c = t.createCriteria();
        tPersonMapper.deleteByExample(t);
    }


    public void addPerson(){
        delActor();
        delCareer();
        addCareer();
        TCareerCriteria t = new TCareerCriteria();
        TCareerCriteria.Criteria c = t.createCriteria();

        int a = 0;
        for(;a<100;a++){
            TPersonWithBLOBs d = new TPersonWithBLOBs();
            d.setId(GenerateKeyUtil.generationPK());
            d.setBirth(DateUtil.shortDate(DateUtil.addDate(new Date(),randomObject(careers),-100+new Random().nextInt(100))));
            d.setCareer(a % 3+1);
            d.setContact(randomString(mobile1)+randomString(mobile2)+randomString(mobile3));
            d.setName(createName());
            d.setDescription(d.getName()+"，"+DateUtil.date2String(DateUtil.getDate(d.getBirth(),"yyyyMMdd"))+"出生于中国XXX省XXX市，歌手、演员、主持人、导演、编剧");
            d.setGender(a%3);
            d.setStatus(0);
            d.setHeight(160+new Random().nextInt(25));
            d.setRepWorks("《代表作品"+a+"》、《代表作品"+(a+1)+"》、《代表作品4》");
            d.setFaceurl(randomString(urls));
            tPersonMapper.insert(d);
        }
    }



    public void addDramas(){
        delDramas();

        delActor();
        addPerson();

        TPersonCriteria t = new TPersonCriteria();
        TPersonCriteria.Criteria c = t.createCriteria();

        c.andCareerEqualTo(1);
        List<TPerson> actors = tPersonMapper.selectByExample(t);

        TPersonCriteria t1 = new TPersonCriteria();
        TPersonCriteria.Criteria c1 = t1.createCriteria();

        c.andCareerEqualTo(3);
        List<TPerson> directors = tPersonMapper.selectByExample(t1);

        int a = 0;
        for(;a<500;a++){
            TDramaWithBLOBs d = new TDramaWithBLOBs();
            d.setTitle(createName()+"录入的剧库");
            d.setName("家有儿女系列"+a);
            d.setTheme(randomString(themes));
            d.setId(GenerateKeyUtil.generationPK());
            d.setActor(createName());
            TPerson actor = randomObject(actors);
            d.setActorId(String.valueOf(actor.getId()));
            d.setActor(actor.getName());
            d.setDescription(randomString(informations));
            d.setChapter(new Random().nextInt(80));
            TPerson director = randomObject(directors);
            d.setDirector(director.getName());
            d.setDirectorId(director.getId());
            d.setCommpany("华谊电影公司喽");
            d.setDramaUrl(randomString(imgUrls));
            d.setDramaUrl1(randomString(imgUrls));
            d.setDramaUrl2(randomString(imgUrls));
            d.setDramaUrl3(randomString(imgUrls));
            d.setDramaUrl4(randomString(imgUrls));
            tDramaMapper.insert(d);
        }
    }

    public void delDramaPerson(){
        TDramaPersonCriteria t = new TDramaPersonCriteria();
        TDramaPersonCriteria.Criteria c = t.createCriteria();
        tDramaPersonMapper.deleteByExample(t);
    }

    public void addDramaPerson(){
        delDramaPerson();

        TPersonCriteria t = new TPersonCriteria();
        TPersonCriteria.Criteria c = t.createCriteria();
        c.andCareerEqualTo(1);

        List<TPerson> actors = tPersonMapper.selectByExample(t);

        TPersonCriteria t1 = new TPersonCriteria();
        TPersonCriteria.Criteria c1 = t1.createCriteria();

        c1.andCareerEqualTo(3);
        List<TPerson> directors = tPersonMapper.selectByExample(t1);

        TDramaCriteria td = new TDramaCriteria();
        TDramaCriteria.Criteria c3 = td.createCriteria();
        List<TDrama> dramas = tDramaMapper.selectByExample(td);

        createPerson(actors, dramas);
        createPerson(directors,dramas);

    }

    private void createPerson(List<TPerson> actors, List<TDrama> dramas) {
        int a = 0;
        for(;a<actors.size();a++){
            TDramaPerson tp = new TDramaPerson();
            tp.setCreateTime(DateUtil.getNow());
            TDrama d = randomObject(dramas);
            tp.setDramaId(d.getId());
            tp.setDramaName(d.getName());
            TPerson p = actors.get(a);
            tp.setcName(p.getCareer()==1?"演员":p.getCareer()==2?"编剧":"导演");
            tp.setcId(p.getCareer());
            tp.setpId(p.getId());
            tp.setpName(p.getName());
            tp.setRamark("由"+p.getName()+"领衔主演");
            tDramaPersonMapper.insert(tp);
            TDramaPerson tp1 = new TDramaPerson();
            tp1.setCreateTime(DateUtil.getNow());
            TDrama d1 = randomObject(dramas);
            tp1.setDramaId(d1.getId());
            tp1.setDramaName(d1.getName());
            TPerson p1 = actors.get(a);
            tp1.setcName(p1.getCareer()==1?"演员":p1.getCareer()==2?"编剧":"导演");
            tp1.setcId(p1.getCareer());
            tp1.setpId(p1.getId());
            tp1.setpName(p1.getName());
            tp1.setRamark("由"+p1.getName()+"领衔主演");
            tDramaPersonMapper.insert(tp1);
        }
        int b = 0;
        for(;b<dramas.size();b++){
            TDramaPerson tp = new TDramaPerson();
            tp.setCreateTime(DateUtil.getNow());
            TDrama d = dramas.get(b);
            tp.setDramaId(d.getId());
            tp.setDramaName(d.getName());
            TPerson p = randomObject(actors);
            tp.setcName(p.getCareer()==1?"演员":p.getCareer()==2?"编剧":"导演");
            tp.setcId(p.getCareer());
            tp.setpId(p.getId());
            tp.setpName(p.getName());
            tp.setRamark("由"+p.getName()+"领衔主演");
            tDramaPersonMapper.insert(tp);
            TDramaPerson tp1 = new TDramaPerson();
            tp1.setCreateTime(DateUtil.getNow());
            TDrama d1 = dramas.get(b);
            tp1.setDramaId(d1.getId());
            tp1.setDramaName(d1.getName());
            TPerson p1 = randomObject(actors);
            tp1.setcName(p1.getCareer()==1?"演员":p1.getCareer()==2?"编剧":"导演");
            tp1.setcId(p1.getCareer());
            tp1.setpId(p1.getId());
            tp1.setpName(p1.getName());
            tp1.setRamark("由"+p1.getName()+"领衔主演");
            tDramaPersonMapper.insert(tp1);
        }
    }


    public String randomString(List<String> list){
        int size = list.size();
        return list.get(new Random().nextInt(size-1));
    }

    public <T> T randomObject(List<T> list){
        int size = list.size();
        return list.get(new Random().nextInt(size-1));
    }

    public String createName(){
        return randomString(first)+randomString(second)+randomString(last);
    }


    /**
     * 新增资讯数据
     * by lizb 2017/10/23
     */
    public void addInformation(){
        delInformation();
        List titleList = new ArrayList();
        titleList.add("甘露<<我的老爸是奇葩>> 化身\"主攻女友,撩你没商量\"");
        titleList.add("曹颖重磅加盟《生命缘》 大方爆料自己曾患焦虑症");
        titleList.add("《我们》收官 关之琳随心随性开启真人秀新大门");
        titleList.add("《火王之千里同风》陈柏霖景甜眼神宠溺甜蜜升级");
        titleList.add("周杰伦删除昆凌与巨石强森合照 背后真相竟是这样");

        List contentList = new ArrayList();
        contentList.add("新浪娱乐讯   上周六晚20：30，《拜见小师父》在千呼万唤中播出了第一集，有网友在官微留言称：节目太短了，希望下期长一点。让观众感到意犹未尽，《拜见小师父》可以说是走出了成功的第一步。然而，节目最大的成功却在于发掘了中国优秀传统文化艺术，让它们获得新生。首期节目中由新疆小师父希尔麦麦提带来的《玛纳斯》表演就是其中的代表。这个一直被忽略的文化明珠终于在《拜见小师父》的舞台上展现出应有的光彩。\n" +
                "\n" +
                "　　随着节目的播出，人们开始搜索和了解这个节目的背景和意义，网络上的评论从开始的好奇“这是什么”逐渐转向“这很有意义”，讨论声量越来越大。\n" +
                "\n" +
                "　　希尔麦麦提带来的这个表演意义就在于表演的内容本身是中国少数民族三大史诗之一的《玛纳斯》。或许有不少人从未听过这个名字，而《拜见小师父》的责任之一，就是将那些传播范围较小的优秀传统文化艺术发掘出来，拂去尘埃，呈现出它本来该有的炫目光彩。此次希尔买买提表演《玛纳斯》，就是一种科普，也是一种有益的宣传，让这个名字重新得到关注。从对于传统文化艺术的保护和挖掘来看，《拜见小师父》做出了值得赞赏的尝试。");

        contentList.add("明星嘉宾重磅加盟 曹颖自曝曾患焦虑症\n" +
                "\n" +
                "　　北京卫视《生命缘》系列节目于2014年开播，以对医疗事件的纪实性表现和对生死观的探讨引起了社会各界的广泛关注，无论在业内还是在观众中都享有良好的口碑，连续两年荣获中国新闻奖一等奖，被称为“一档影响亿万中国人生死观的节目”。\n" +
                "\n" +
                "　　而本季《生命缘·生命的礼物》则在原来的基础上对内容和形式进行了重磅升级。节目突破了医疗纪实类节目的调性，从过去以手术为主、悲情的叙述方式升级成以治愈为主，呈现阳光、温暖的基调；从过去的身体治愈到现在的心灵治愈；从过去单一的医院病房升级为12间各式各样的“阳光病房”。明星嘉宾的加盟则带领观众从客观的视角去探寻生命背后情感的力量，也将为观众开启不同的生命体验。\n" +
                "\n" +
                "　　即将在今晚播出的首期节目中，节目组将带我们重回丹丹的家庭。6岁女孩丹丹突发颅内恶性肿瘤离开人世，她的父母为了满足她生前的愿望，捐献了她的器官，让3个孩子重获新生，2个孩子重见光明。此前《生命缘》将丹丹的故事拍成一期名为《请你替我活下去》的节目，引发观众、网友的广泛关注，腾讯视频两天内播放量破千万。丹丹的善举甚至改变了人们对器官捐献的态度，很多网友表示自己也会选择进行器官捐献。");

        contentList.add("出道几十年，出演过“十三姨”、“任盈盈”、“蓝小蝶”等经典角色的关之琳是许多人心中永远的女神。息影后的内地综艺首秀，关之琳却有意放下过去的“光环”，“让观众认识一个真实的，不同于银幕上的关之琳”。于是，我们看到了一个会滑雪、会架子鼓的全能女神，也看到了一个勇敢尝试芭蕾舞、秦腔，对新鲜事物抱有极大热情的关之琳。不断刷新的技能树也让观众看到了一个敢想敢做、有着多彩人生的关之琳。");
        contentList.add("据了解，此次的《火王之千里同风》不仅是陈柏霖暌违荧屏多年的又一力作，更是景甜首度挑战时装剧集。该剧融汇了爱情、商战、软科幻、悬疑等元素于一体，自开拍以来便备受网友瞩目。剧中，陈柏霖饰演了高冷总裁林烨，在一次工作中偶遇了由景甜饰演的热血记者童风，二人在一次次误会中相识相知，展开了一段浪漫、虐心的爱情故事。在此次曝光的剧照中，陈柏霖诠释“林烨”一角，面对工作桀骜霸气，面对感情温暖贴心，此次与景甜再度默契携手，上演了一出浪漫虐狗大戏。景甜饰演的“童风”则以甜美记者造型亮相，微卷短发再添少女气息，与赖雨濛、张维娜组成的“闺蜜团”也是羡煞众人。而张逸杰赖雨濛则延续二人以往的甜蜜CP风，张逸杰此次褪去青涩，成为新一代学霸男神“雷昊”，赖雨濛则生动演绎了大明星“魏咏倩”的日常，古灵精怪鬼马可爱。另外，演员杜俊泽[微博]、孙绍龙、刘海蓝都在此次曝光的剧照中惊喜亮相，阵容亮眼令粉丝更添期待。\n" +
                "\n" +
                "　　《火王之千里同风》转战冰岛实景拍摄，未播先火“花落”湖南卫视");

        contentList.add("据台湾媒体报道，吴尊近期带着1对儿女Max、Neinei一起上《爸爸去哪儿5》，暖男形象深受欢迎，私底下的他不只宠爱2个小孩，也很疼惜妻子，尽管小俩口从相识到现在，已经走过22个年头，感情甜蜜如初，有网友挖出他几年前上节目的片段，听着老婆悄悄写好的亲笔信，“不管你在哪儿，千万不要感觉孤单”，不禁眼眶泛泪。\n" +
                "吴尊曾上知名访谈节目《鲁豫有约》畅谈家庭生活，鲜少人知的是一家四口其实只有两个生日，他和Neinei同天生日，老婆则和Max同天生日，全是颜值超高的天秤座，他坦言这其实经过刻意安排，也觉得很幸运，“因为我身边有很多朋友，要有小孩不是说你要有就有。”\n" +
                "虽然第一个小孩顺利出生，但吴尊谈到“第二个小孩”时，突然变得有点难以启齿，这才坦言其实在Max之前，“我们还有一个”，老婆2个月时不幸流产，又刚好碰到他工作走不开，语气神情间满是懊悔与不舍。");

        delInformation();
        for(int i = 0,total=800;i<total;i++){
            TInformationWithBLOBs information = new TInformationWithBLOBs();
            information.setId(GenerateKeyUtil.generationPK());
            information.setTitle((String) titleList.get(i%5));
            information.setContent((String) contentList.get(i%5));
            information.setAuthor(first.get(i%10) + second.get(i%10));
            information.setStatus(0);
            information.setNavType(i%6);
            information.setFloorType(randomString(ApiFloorEnum.getFloor()));
            //information.setIsIntro(0);
            //information.setIsShow(0);
            information.setFromType(String.valueOf(i%2));
            information.setReprintFrom("123456");
            information.setVideoUrl("http://v.youku.com/v_show/id_XNTkzNTM1ODU2.html");
            information.setCoverUrl(randomString(imgUrls));
            information.setCreateTime(DateUtil.getNow());
            information.setUpdateTime(DateUtil.getNow());
            information.setPublishTime(randomDateBetweenMinAndMax());
            information.setCreater(first.get(i%10) + last.get(i%10));
            informationMapper.insert(information);
        }
        for(int i = 0,total=100;i<total;i++){
            TInformationWithBLOBs information = new TInformationWithBLOBs();
            information.setId(GenerateKeyUtil.generationPK());
            information.setTitle((String) titleList.get(i%5));
            information.setContent((String) contentList.get(i%5));
            information.setAuthor(first.get(i%10) + second.get(i%10));
            information.setStatus(0);
            information.setNavType(ApiClassifyEnum.RECOMMEND.getIndex());
            information.setFloorType(ApiFloorEnum.getFloor().get(i%3));
            //information.setIsIntro(0);
            //information.setIsShow(0);
            information.setFromType(String.valueOf(i%2));
            information.setReprintFrom("123456");
            information.setVideoUrl("http://v.youku.com/v_show/id_XNTkzNTM1ODU2.html");
            information.setCoverUrl(randomString(imgUrls));
            information.setCreateTime(DateUtil.getNow());
            information.setUpdateTime(DateUtil.getNow());
            information.setPublishTime(randomDateBetweenMinAndMax());
            information.setCreater(first.get(i%10) + last.get(i%10));
            informationMapper.insert(information);
        }
        for(int i = 0,total=5;i<total;i++){
            TInformationWithBLOBs information = new TInformationWithBLOBs();
            information.setId(GenerateKeyUtil.generationPK());
            information.setTitle((String) titleList.get(i%5));
            information.setContent((String) contentList.get(i%5));
            information.setAuthor(first.get(i%10) + second.get(i%10));
            information.setStatus(0);
            information.setNavType(i%6);
            information.setFloorType(ApiFloorEnum.TOP.getValue());
            //information.setIsIntro(0);
            //information.setIsShow(0);
            information.setFromType(String.valueOf(i%2));
            information.setReprintFrom("123456");
            information.setVideoUrl("http://v.youku.com/v_show/id_XNTkzNTM1ODU2.html");
            information.setCoverUrl(randomString(imgUrls));
            information.setCreateTime(DateUtil.getNow());
            information.setUpdateTime(DateUtil.getNow());
            information.setPublishTime(randomDateBetweenMinAndMax());
            information.setCreater(first.get(i%10) + last.get(i%10));
            informationMapper.insert(information);
        }
        for(int i = 0,total=2;i<total;i++){
            TInformationWithBLOBs information = new TInformationWithBLOBs();
            information.setId(GenerateKeyUtil.generationPK());
            information.setTitle((String) titleList.get(i%5));
            information.setContent((String) contentList.get(i%5));
            information.setAuthor(first.get(i%10) + second.get(i%10));
            information.setStatus(0);
            information.setNavType(ApiClassifyEnum.RECOMMEND.getIndex());
            information.setFloorType(ApiFloorEnum.TOP.getValue());
            //information.setIsIntro(0);
            //information.setIsShow(0);
            information.setFromType(String.valueOf(i%2));
            information.setReprintFrom("123456");
            information.setVideoUrl("http://v.youku.com/v_show/id_XNTkzNTM1ODU2.html");
            information.setCoverUrl(randomString(imgUrls));
            information.setCreateTime(DateUtil.getNow());
            information.setUpdateTime(DateUtil.getNow());
            information.setPublishTime(randomDateBetweenMinAndMax());
            information.setCreater(first.get(i%10) + last.get(i%10));
            informationMapper.insert(information);
        }
    }

    /**
     * 删除资讯
     */
    public void delInformation(){
        TInformationCriteria example = new TInformationCriteria();
        TInformationCriteria.Criteria c = example.createCriteria();
        informationMapper.deleteByExample(example);
    }

    public void delComment(){
        TCommentCriteria example = new TCommentCriteria();
        TCommentCriteria.Criteria c = example.createCriteria();
        commentMapper.deleteByExample(example);
    }

    public void addComment(){
        delAdmin();
        addAdmin();
        long informationId = 2017103011410200000L;
        int a = 0;
        TAdminCriteria t = new TAdminCriteria();
        TAdminCriteria.Criteria c = t.createCriteria();
        List<TAdmin> admins = tAdminMapper.selectByExample(t);
        for(;a<5;a++){
            TComment comment = new TComment();
            comment.setCreateTime(randomDateBetweenMinAndMax());
            comment.setId(GenerateKeyUtil.generationPK());
            comment.setInformationId(informationId);
            comment.setUrl(randomObject(urls));
            comment.setUserId(admins.get(a).getId());
            comment.setUserName(admins.get(a).getUserName());
            comment.setContent(randomString(contents));
            commentMapper.insert(comment);
        }
    }

    public void delAdmin(){
        TAdminCriteria t = new TAdminCriteria();
        TAdminCriteria.Criteria c = t.createCriteria();
        c.andIdNotEqualTo(11111L);
        tAdminMapper.deleteByExample(t);
    }

    public void addAdmin(){
        int a = 0;
        for(;a<15;a++){
            TAdmin admin = new TAdmin();
            admin.setId(GenerateKeyUtil.generationPK());
            admin.setFaceUrl(randomObject(urls));
            admin.setPassword("123456");
            admin.setGender(a%2);
            admin.setMobile(randomObject(mobile1)+randomObject(mobile2)+randomObject(mobile3));
            admin.setUserName("test"+a);
            admin.setNickName(createName());
            tAdminMapper.insert(admin);
        }

        TAdmin admin = new TAdmin();
        admin.setUserName("wangxq");
        admin.setPassword("123456");
        admin.setNickName("王学谦");
        admin.setId(22222L);
        admin.setGender(0);
        admin.setFaceUrl(randomString(urls));
        admin.setMobile(randomObject(mobile1)+randomObject(mobile2)+randomObject(mobile3));
        tAdminMapper.insert(admin);
    }

    public void delCmsHome() {
        TCmsHomeCriteria t = new TCmsHomeCriteria();
        TCmsHomeCriteria.Criteria c= t.createCriteria();
        tCmsHomeMapper.deleteByExample(t);
    }

    public void addCmsHome(){
        int a = 0;
        TAdminCriteria t = new TAdminCriteria();
        TAdminCriteria.Criteria c= t.createCriteria();
        List<TAdmin> admins = tAdminMapper.selectByExample(t);

        TInformationCriteria ti = new TInformationCriteria();
        TInformationCriteria.Criteria ci = ti.createCriteria();
        ti.setLimitStart(0);
        ti.setLimitEnd(100);
        List<TInformation> informations = tInformationMapper.selectByExample(ti);
        for(;a<100;a++){
            TCmsHome cmsHome = new TCmsHome();

            cmsHome.setCreateId(randomObject(admins).getId());
            cmsHome.setUpdateId(randomObject(admins).getId());
            cmsHome.setCreateTime(DateUtil.getNow());
            cmsHome.setFromId(informations.get(a).getId());
            cmsHome.setFromTitle(informations.get(a).getTitle());

            cmsHome.setType(TypeConstants.CmsResource.INFOR_TYPE);
            cmsHome.setId(GenerateKeyUtil.generationPK());
            cmsHome.setStatus(TypeConstants.COMMON_INVALID);
            cmsHome.setImgUrl(randomString(imgUrls));
            tCmsHomeMapper.insert(cmsHome);
        }
    }

    public static String randomDateBetweenMinAndMax(){
        Calendar calendar = Calendar.getInstance();
        //注意月份要减去1
        calendar.set(2017,9,31);
        calendar.getTime().getTime();
        //根据需求，这里要将时分秒设置为0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND,0);
        long min = calendar.getTime().getTime();;
        calendar.set(2017,10,31);
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        calendar.getTime().getTime();
        long max = calendar.getTime().getTime();
        //得到大于等于min小于max的double值
        double randomDate = Math.random()*(max-min)+min;
        //将double值舍入为整数，转化成long类型
        calendar.setTimeInMillis(Math.round(randomDate));
        return DateUtil.longDateGB(calendar.getTime());
    }

    //修正information数据
    public void updateCoverUrl(PageReq page){

        TInformationCriteria t = new TInformationCriteria();
        TInformationCriteria.Criteria ct = t.createCriteria();

        //上下架
        ct.andIsShowEqualTo(TypeConstants.AppConstants.IF_INFO_SHOW);
        //翻页
        t.setLimitStart(0);
        t.setLimitEnd(100);

        informationService.orderByAndSetId(page, t, ct);

        List<TInformationWithBLOBs> ts = tInformationSelfMapper.selectByExampleWithBLOBs(t);

        //迭代失败条件
        if(CollectionUtils.isEmpty(ts))  return;

        TInformationWithBLOBs flag = new TInformationWithBLOBs();

        for(TInformationWithBLOBs art:ts){
            informationService.setInformationSliderStyleImgUrl(art);
            TInformationCriteria temp = new TInformationCriteria();
            TInformationCriteria.Criteria ctemp = temp.createCriteria();
            ctemp.andIdEqualTo(art.getId());
            tInformationMapper.updateByExampleWithBLOBs(art,temp);
            flag.setId(art.getId());
            logger.info("【"+art.getId()+"：咨询】更新成功");
        }


        //迭代
        page.setDataId(flag.getId());
        page.setHandle(ApiOperateEnum.DOWN.getName());
        updateCoverUrl(page);
    }
}
